import 'dart:async';
import 'dart:ui';

import 'package:example/controller/app_controller.dart';
import 'package:flutter/material.dart';
import 'package:jm_flutter/jm_flutter.dart';

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  final tag = "HomePage";

  String dropdownValue = 'system';

  AppController appController = findApp;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    logd(tag, "i18n:" + "为了更好的体验与使用".i18n);
    //AppVersion.init();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: JmColors.bg,
      body: SafeArea(
        child: SingleChildScrollView(
          child: Container(
            padding: const EdgeInsets.all(10),
            child: Column(
              children: [
                MyContainer(
                  padding: const EdgeInsets.all(10),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      MyText(
                        "Show",
                        size: 20,
                        weight: FontWeight.bold,
                      ),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                        children: [
                          MyButton(
                            onPressed: () {
                              Show.snackbar("Hi", "测试测试");
                            },
                            text: "snackbar",
                          ),
                          MyButton.outlined(
                            text: "测试",
                            //color: JmColors.main,
                            onPressed: () {},
                          ),
                          MyIconButton(
                            icon: const Icon(Icons.add),
                            onPressed: () {},
                            color: Colors.blueAccent,
                            backgroundColor: JmColors.bg,
                          ),
                          OutlinedButton(
                            onPressed: () {
                              Show.toast("测试测试");
                            },
                            child: MyText("toast"),
                          ),
                        ],
                      ),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                        children: [
                          OutlinedButton(
                            onPressed: () {
                              Show.success("测试测试");
                            },
                            child: MyText("success"),
                          ),
                          OutlinedButton(
                            onPressed: () {
                              Show.error("测试测试");
                            },
                            child: MyText("error"),
                          ),
                          OutlinedButton(
                            onPressed: () {
                              Show.info("测试测试");
                            },
                            child: MyText("info"),
                          ),
                        ],
                      ),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                        children: [
                          OutlinedButton(
                            onPressed: () {
                              Show.dismiss();
                            },
                            child: MyText("关闭"),
                          ),
                          OutlinedButton(
                            onPressed: () {
                              Show.loading(str: "测试测试");
                            },
                            child: MyText("loading"),
                          ),
                          OutlinedButton(
                            onPressed: () {
                              int i = 0;
                              Timer.periodic(Duration(milliseconds: 50),
                                  (timer) {
                                i++;
                                if (i > 99) {
                                  i = 0;
                                  timer.cancel();
                                  Show.dismiss();
                                  return;
                                }
                                Show.progress(
                                    i / 100, "测试测试:" + i.toString() + "%");
                              });
                            },
                            child: MyText("progress"),
                          ),
                        ],
                      ),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                        children: [
                          OutlinedButton(
                            onPressed: () {
                              // Get.defaultDialog(
                              //   onConfirm: () {
                              //     back();
                              //   },
                              //   onCancel: () {
                              //     back();
                              //   },
                              //   buttonColor: Colors.white,
                              //   middleText: "Dialog made in 3 lines of code",
                              // );
                            },
                            child: MyText("Dialog"),
                          ),
                          OutlinedButton(
                            onPressed: () {
                              // Get.bottomSheet(Container(
                              //   decoration: BoxDecoration(color: Colors.red),
                              //   child: Wrap(
                              //     children: <Widget>[
                              //       ListTile(
                              //           leading: Icon(Icons.music_note),
                              //           title: Text('Music'),
                              //           onTap: () {}),
                              //       ListTile(
                              //         leading: Icon(Icons.videocam),
                              //         title: Text('Video'),
                              //         onTap: () {},
                              //       ),
                              //     ],
                              //   ),
                              // ));
                            },
                            child: MyText("bottomSheet"),
                          ),
                          OutlinedButton(
                            onPressed: () {
                              Widget baseAlertDialog = MyDialog(
                                title: "发现新版本",
                                middleText: "你好，请问需要市场吗?",
                                //leftButtonText: "暂不升级",
                                //rightButtonText: "立即升级",
                                rightButtonColor: Colors.redAccent,
                                //middle: Container(padding: EdgeInsets.only(top: 10,bottom: 10),child: MyImage("assets/img/baidu.png")),
                                onLeftTap: () {
                                  back();
                                },
                                onRightTap: () {
                                  back();
                                },
                              );
                              //Get.dialog(baseAlertDialog);
                            },
                            child: MyText("自定义Dialog"),
                          ),
                        ],
                      ),
                      MyBigButton(
                          //text: "测试测试",
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                          children: [
                          Icon(Icons.add),
                          MyText("开始"),
                        ],),
                          //textColor: Colors.white,
                          //color: Colors.blueAccent,
                          height: 60,
                          radius: 10,
                          margin: const EdgeInsets.only(left: 80,right: 80,top: 20),

                          onPressed: (){

                      },),
                    ],
                  ),
                ),
                gapv(10),
                MyContainer(
                  padding: const EdgeInsets.all(10),
                  width: double.infinity,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      MyText(
                        "路由",
                        size: 20,
                        weight: FontWeight.bold,
                      ),
                      gapv(10),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                        children: [
                          OutlinedButton(
                            onPressed: () {
                              AppVersion.getNew();
                            },
                            child: MyText("获取APP版本"),
                          ),
                          OutlinedButton(
                            onPressed: () {
                              AppVersion.getNew(isShowDialog: false);
                            },
                            child: MyText("获取APP版本，无弹窗"),
                          ),
                        ],
                      ),
                      OutlinedButton(
                        onPressed: () {
                          //Get.to(() => CrossOnePage());
                        },
                        child: MyText("进入测试页A"),
                      ),
                      OutlinedButton(
                        onPressed: () {
                          gotoNamed(JmPages.appLanguagePage);
                        },
                        child: MyText("进入语言设置"),
                      ),
                      OutlinedButton(
                        onPressed: () {
                          gotoNamed(JmPages.aboutPage);
                        },
                        child: MyText("进入关于页面"),
                      ),
                      OutlinedButton(
                        onPressed: () {
                          // Get.toNamed(Routes.webviewPage,parameters: {
                          //   "url":"https://www.jianshu.com/p/50e20d2b2285",
                          //   "title":"隐私政策",
                          // });
                        },
                        child: MyText("进入Webview页面"),
                      ),
                    ],
                  ),
                ),
                gapv(10),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
